/* 
 * Copyright (C) 2014 Ningbo Yuanqun Inc., All Rights Reserved. 
 */
package com.yuanqunsoft.alimigration.engine.vo;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

import com.fasterxml.jackson.annotation.JsonProperty;

/**
 * <p>
 * 一个实例代表了一条规则和其所对应的扫描结果
 * </p>
 * 
 * @author ShaoYu
 * @version 1.0
 */
public class ScanResult implements Serializable {
    /**
	 * 
	 */
    private static final long serialVersionUID = 3205366578970841152L;

    @JsonProperty(value = "rulName")
    private String ruleName;
    private List<Alert> alerts;

    public ScanResult() {

    }

    public ScanResult(String ruleName) {
        this.ruleName = ruleName;
        alerts = new ArrayList<Alert>();
    }

    public boolean addAlert(Alert alert) {
        return alerts.add(alert);
    }

    public boolean addAlert(String resource, int line) {
        return alerts.add(new Alert(resource, line));
    }

    public boolean empty() {
        return alerts.size() == 0 ? true : false;
    }

    public String getRuleName() {
        return ruleName;
    }

    public void setRuleName(String ruleName) {
        this.ruleName = ruleName;
    }

    public List<Alert> getAlerts() {
        return alerts;
    }

    public void setAlerts(List<Alert> alerts) {
        this.alerts = alerts;
    }

    @Override
    public int hashCode() {
        final int prime = 31;
        int result = 1;
        result = prime * result + ((alerts == null) ? 0 : alerts.hashCode());
        result = prime * result + ((ruleName == null) ? 0 : ruleName.hashCode());
        return result;
    }

    @Override
    public boolean equals(Object obj) {
        if (this == obj)
            return true;
        if (obj == null)
            return false;
        if (getClass() != obj.getClass())
            return false;
        ScanResult other = (ScanResult) obj;
        if (alerts == null) {
            if (other.alerts != null)
                return false;
        } else if (!alerts.equals(other.alerts))
            return false;
        if (ruleName == null) {
            if (other.ruleName != null)
                return false;
        } else if (!ruleName.equals(other.ruleName))
            return false;
        return true;
    }

    @Override
    public String toString() {
        return "ScanResult [ruleName=" + ruleName + ", alerts=" + alerts + "]";
    }

}
